﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
	[TestClass]
	public class UserData_53_CommunicationAddressS3_Test
	{
		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test01_Equals_StringVariant()
		{
			UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3("0221ABCD", false);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// different derived type
				UserData_51_ManufacturerId userData2Compare = new UserData_51_ManufacturerId(String.Empty);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different derived type
				ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
				UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(userData.GetCopyOfAsciiBytes(), userData.RelativeAddress);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different length
				byte[] asciiBytes = userData.GetCopyOfAsciiBytes();
				byte[] asciiBytes2Compare = new byte[asciiBytes.Length + 1];
				for (int index = 0; index < asciiBytes.Length; index++)
				{
					asciiBytes2Compare[index] = asciiBytes[index];
				}

				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(asciiBytes2Compare, userData.RelativeAddress);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different single byte value
				byte[] asciiBytes = userData.GetCopyOfAsciiBytes();
				byte[] asciiBytes2Compare = new byte[asciiBytes.Length];
				asciiBytes2Compare[0] = (byte)(asciiBytes[0] + 1);
				for (int index = 1; index < asciiBytes.Length; index++)
				{
					asciiBytes2Compare[index] = asciiBytes[index];
				}

				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(asciiBytes2Compare, userData.RelativeAddress);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different relative address flag
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(userData.GetCopyOfAsciiBytes(), !userData.RelativeAddress);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test02_Equals_StringEmpty()
		{
			UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(String.Empty, true);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				// same object - equal
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(String.Empty, userData.RelativeAddress);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different derived type 
				ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
				UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(userData.GetCopyOfAsciiBytes(), userData.RelativeAddress);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test03_Equals_StringNull()
		{
			string dummyString = null;
			UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(dummyString, true);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(String.Empty, userData.RelativeAddress);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different derived type 
				ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
				UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(userData.GetCopyOfAsciiBytes(), userData.RelativeAddress);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test04_Equals_BytesVariant()
		{
			byte[] addressBytes = new byte[5];
			addressBytes[0] = 0x44;
			addressBytes[1] = 0x48;
			addressBytes[2] = 0x49;
			addressBytes[3] = 0x4a;
			addressBytes[4] = 0x4b;

			UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, false);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(String.Empty, userData.RelativeAddress);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different derived type 
				ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
				UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// same object - equal
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(userData.GetCopyOfAsciiBytes(), userData.RelativeAddress);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different length
				byte[] asciiBytes = userData.GetCopyOfAsciiBytes();
				byte[] asciiBytes2Compare = new byte[asciiBytes.Length + 1];
				for (int index = 0; index < asciiBytes.Length; index++)
				{
					asciiBytes2Compare[index] = asciiBytes[index];
				}

				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(asciiBytes2Compare, userData.RelativeAddress);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

			{
				// different single byte value
				byte[] asciiBytes = userData.GetCopyOfAsciiBytes();
				byte[] asciiBytes2Compare = new byte[asciiBytes.Length];
				asciiBytes2Compare[0] = (byte)(asciiBytes[0] + 1);
				for (int index = 1; index < asciiBytes.Length; index++)
				{
					asciiBytes2Compare[index] = asciiBytes[index];
				}

				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(asciiBytes2Compare, userData.RelativeAddress);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test05_Equals_BytesNull()
		{
			byte[] addressBytes = null;
			UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, false);

			{
				// completely different type - NOT equal
				object dummyObject = new object();
				Assert.IsFalse(userData.Equals(dummyObject));
			}

			{
				UserData_53_CommunicationAddressS3 userData2Compare = new UserData_53_CommunicationAddressS3(String.Empty, userData.RelativeAddress);
				Assert.IsTrue(userData.Equals(userData2Compare));
			}

			{
				// different derived type 
				ReportType_Device reportType = new ReportType_Device(false, eReportSubType_Device.General);
				UserData userData2Compare = new UserData_02_StatusChangeReport2Confirm(0x01, 0x02, 0x03, eAddressExtension_1.Input, reportType);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test06_GetHashCode()
		{
			{
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3("0221ABCD", false);
				int hashCode = userData.GetHashCode();
			}

			{
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(String.Empty, true);
				int hashCode = userData.GetHashCode();
			}

			{
				string dummyString = null;
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(dummyString, true);
				int hashCode = userData.GetHashCode();
			}

			{
				byte[] addressBytes = new byte[5];
				addressBytes[0] = 0x44;
				addressBytes[1] = 0x48;
				addressBytes[2] = 0x49;
				addressBytes[3] = 0x4a;
				addressBytes[4] = 0x4b;

				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, false);
				int hashCode = userData.GetHashCode();
			}

			{
				byte[] addressBytes = null;
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, false);
				int hashCode = userData.GetHashCode();
			}

			{
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3("This address is too long but we call the constructor anyway and see what happens...", false);
				int hashCode = userData.GetHashCode();
			}

			{
				// too many bytes
				byte[] addressBytes = new byte[500];
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, true);
				int hashCode = userData.GetHashCode();
			}
		}

		[TestMethod]
		[Owner("Frank Eppink")]
		public void Test07_ToString()
		{
			{
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3("0221ABCD", false);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(String.Empty, true);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				string dummyString = null;
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(dummyString, true);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				byte[] addressBytes = new byte[5];
				addressBytes[0] = 0x44;
				addressBytes[1] = 0x48;
				addressBytes[2] = 0x49;
				addressBytes[3] = 0x4a;
				addressBytes[4] = 0x4b;

				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, false);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				byte[] addressBytes = null;
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, false);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3("This address is too long but we call the constructor anyway and see what happens...", false);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}

			{
				byte[] addressBytes = new byte[500];
				UserData_53_CommunicationAddressS3 userData = new UserData_53_CommunicationAddressS3(addressBytes, true);
				string stringResult = userData.ToString();
				Assert.IsNotNull(stringResult);
			}
		}
	}
}
